<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<?php echo validation_errors('<p id="nav" class="error">'); ?>
<div id="nav">
<h2>Add Products to the Order</h2>
<span>To create an order you must add products and container to the order.</span><br /><br />

<h3>Step 2</h3>
<span>Now Please add any products to your order/shipment</span><br/>

<br/>Editing Order ID: <?php
//if(!is_array($orderID)){
//$orderID = $this->product_model->getOrderID($orderID);}

foreach($orderID as $rows) : 
echo $rows->id;
$id = $rows->id;
$name = $rows->name;
?> 
<br/>Order Name: <?php echo $rows->name; ?>
<?php endforeach;?><br /><br />
  <form id="hidden_form" style="display:none" method="post">
    <input type="hidden" name="product_id" />
    <input type="hidden" name="amount1" />
    <input type="hidden" name="amount" />
    <input type="hidden" name="divAmount" />
  </form>

<table border="0" cellspacing="0" cellpadding="0" width="99%" class="resultTable" id="datatable">

  <thead> <tr>
                        <th colspan="8">
                        <div id="search">
        <label for="filter">Search For Product:</label> <input type="text" name="filter" value="" id="filter" />
      </div> </th></tr>
<tr>
<th>Product ID</th>
<th>UPC</th>
<th>Description</th>
<th>Model</th>
<th>Box</th>
<th>Per Product</th>
<th>MC</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if(isset($records)) : foreach($records as $row) :
 echo "<tr>";
 echo "<td>".$row->id."</td>";
 echo "<td>".$row->upc."</td>";
  echo "<td>".$row->desc."</td>";
   echo "<td>".$row->model."</td>";
    echo "<td>".$row->product_MC."</td>";
  
    echo "<td>";
  	$data = array(
              'name'        => "amount1",
              'size'        => '5'
            );
	echo form_input($data);
	
	$hidden = array('productID' => $row->id, 'orderID' => $id, 'divAmount' => $row->product_MC);
  	echo form_open("start/addProduct/$id", '', $hidden);
    echo "</td>";
    echo "<td>";
    
    $data = array(
              'name'        => "amount",
              'size'        => '5'
            );
    echo form_input($data);
    echo "</td>";
    echo "<td>";
  echo form_submit('submit', 'Add to Order');
echo form_close();    
echo "</td>"; 
 echo "</tr>"; 
 endforeach;
else : ?>	
	<br/><br/><tr>No records were returned.</tr> <br/>
	<?php endif; ?>
  </tbody>
</table>
</div>
<?php
if(isset($order)){
?>
<div id="nav">
<h2>Order Overview</h2>
<table border="0" cellspacing="0" cellpadding="0" width="99%" class="list">
  <thead>
<tr>
<th>Product Name</th>
<th>Quantity</th>
<th>Volume (MT3)</th>
<th>Weight (lb)</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<?php
$conversion = 0.000016387064;
$finalVolume = 0;
$finalWeight = 0;
 if(isset($order)) : foreach($order as $rows) :
 


 $tempVolume = number_format($rows->Amount*$this->product_model->calculateVolume($rows->productID)*$conversion, 2, '.', '');
 
 //echo $tempVolume;
 
 $finalVolume += $rows->Amount*$this->product_model->calculateVolume($rows->productID)*$conversion;
 $finalWeight += number_format($this->product_model->calculateWeight($rows->productID)*$rows->Amount, 2, '.', '');
 
 $this->product_model->add_volume($rows->productID, $tempVolume, $id);
 echo "<tr>";
 echo "<td>";
 $name = $this->product_model->get_prod_name($rows->productID);
 $prod = $rows->productID;
 foreach($name as $rows2) :
 //print_r($name);
 echo $rows2->desc."</td>";
 echo "<td>".$rows->Amount."</td>";
 echo "<td>".$tempVolume."</td>";
 echo "<td>".number_format($this->product_model->calculateWeight($rows->productID)*$rows->Amount, 2, '.', '')."</td>"; 
 echo "<td>";
    echo anchor("start/del_fromOrder/$id/$prod", "X");
    echo "</td>"; 
 echo "</tr>"; 
 ?>
 <?php 
 endforeach; 
 	 endforeach;
 ?>
 <?php else : ?>	
	<tr>No records were returned.</tr>
	<?php endif; ?>
  </tbody>
  <tfoot>
  <th colspan="8"><div id="search">
  <span>Total Volume: 
  <?php 
  $volume = number_format($finalVolume, 2, '.', '');
  echo $volume." MT3 <br />";
  
  
  echo "Total Weight: ". $finalWeight. " (lb) <br />"; 
  echo "40HQ: ";
  
  function percent($num_amount, $num_total) {
	$count1 = $num_amount / $num_total;
	$count2 = $count1 * 100;
	$count = number_format($count2, 0);
	echo $count."%";
	}
	
	$cont = 63;
	percent($finalVolume, $cont);
   echo "<br />40: ";
   $cont = 56;
   percent($finalVolume, $cont);
   echo "<br />20: ";
   $cont = 26;
   percent($finalVolume, $cont);
   
  ?><br /><br /></span>
        <?php
         $hidden = array('volume' => $volume,'weight'=> $finalWeight, 'orderID' => $id);
  	echo form_open("start/finalize_order/$id", '', $hidden);
   echo form_submit('submit', 'Finalize Order');
echo form_close();
  ?> </div> </th>
        </tfoot>
</table>
</div>
<?php } ?>
<script type="text/javascript" src="<?php echo base_url();?>application/views/application.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>application/views/perProd.js"></script>